﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;

    public class OptionButton extends GameSprite {

        public var selectedImage:Class;
        public var nonSelectedImage:Class;
        public var hoverImage:Class;
        protected var m_selected:Boolean = false;
        protected var m_down:Boolean = false;
        protected var m_over:Boolean = false;

        public function OptionButton(_arg1:Class, _arg2:Class, _arg3:Class, _arg4:Function=null){
            this.selectedImage = _arg1;
            this.nonSelectedImage = _arg3;
            this.hoverImage = _arg2;
            addEventListener(MouseEvent.CLICK, this.onClick, false, 10);
            addEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDown);
            addEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
            addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            if (_arg4 != null){
                addEventListener(MouseEvent.CLICK, _arg4);
            };
            this.buttonMode = true;
            this.useHandCursor = true;
            this.updateImageState();
        }
        public function set selected(_arg1:Boolean):void{
            if (this.m_selected != _arg1){
                this.m_selected = _arg1;
                this.updateImageState();
            };
        }
        public function updateImageState():void{
            var _local1:Class;
            while (this.numChildren > 0) {
                this.removeChildAt(0);
            };
            if (this.m_over){
                _local1 = this.hoverImage;
            } else {
                if (this.selected){
                    _local1 = this.selectedImage;
                } else {
                    _local1 = this.nonSelectedImage;
                };
            };
            addChild(new (_local1)());
        }
        public function get selected():Boolean{
            return (this.m_selected);
        }
        protected function onClick(_arg1:MouseEvent):void{
            this.selected = !(this.selected);
        }
        protected function onMouseOver(_arg1:MouseEvent):void{
            this.m_over = true;
            this.updateImageState();
        }
        protected function onMouseOut(_arg1:MouseEvent):void{
            this.m_over = false;
            this.updateImageState();
        }
        protected function onMouseDown(_arg1:MouseEvent):void{
            this.m_down = true;
            this.x = (this.x + 1);
            this.y = (this.y + 1);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
        }
        protected function onMouseUp(_arg1:MouseEvent):void{
            if (this.m_down){
                this.x = (this.x - 1);
                this.y = (this.y - 1);
            };
            this.m_down = false;
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
        }

    }
}//package Display 
